<?php
class Administrator_Model_User_User extends Administrator_Model_System {
	public $_name = "user";
	protected $_sequence = true;
	public function getAll() {
		$result = $this->select();
		return $this->fetchAll($result)->toArray();	

	}
	public function getRecentUser($num){
		$result = $this->select();
		$result->order("created_date DESC");
		$result->limit($num,0);
		return $this->fetchAll($result)->toArray();	
	}
	public function CheckValidPass($id, $oldpass) {
		$query = $this->select();
		$query->where('id = ?',$id);
		$result = $this->fetchRow($query)->toArray();
		if($result['password']==md5($oldpass))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	public function getItemId($id){
		$result = $this->select();
		$result->where('id = ?',$id);
		return $this->fetchRow($result)->toArray();
	}
	static function getNamebyId($id)
	{
		$excute = new Administrator_Model_User_User();
		$query = $excute->select();
		$query->where('id = ?',$id);
		$result = $excute->fetchRow($query)->toArray();
		return $result['name'];
	}
	public function GetAllUserSercure() {
		$sql = $this->select();
		$result = $sql->where('type != 1');
		return $this->fetchAll($result)->toArray();
	}
	public function insertItem($data)
	{
		try {
		    $this->insert($data);
		} 
		catch (Exception $e) {
		    return $e->getMessage();
		}
		return "success";
		
	}
	public function updateItem($data,$id){
		try {
		    $this->update($data, "id = $id");
		} 
		catch (Exception $e) {
		    return $e->getMessage();
		}
		return "success";
	}
}